#ifndef CLIENTTRANSFER_H
#define CLIENTTRANSFER_H


#include <QObject>
#include <QUdpSocket>
#include <QTimer>
#include <QMutex>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include "protocol.h"

class ClientTransfer : public QObject
{
    Q_OBJECT
public:
    ClientTransfer();
public slots:
    void setServer(QHostAddress addr, quint16 sync_port, quint16 info_port, quint16 data_port);
    void timerRequest();
    void recvInfoResponse();
    void recvSyncResponse();
    void recvDataResponse();
    void imgRequest(unsigned int timestamp, int seq, int width, int height, int state, int speed);
    void trackRequest(int timestamp, int x1, int y1, int x2, int y2);
    void ptzRequest(int x, int y, int z);
    void cameraRequest(int b, int c, int h, int s, int r);
signals:
    void gotResponse(QByteArray response);
    void gotImageData(QByteArray image_data);

private:
    void processDatagram(QByteArray datagram);
    void sendSyncRequest(QByteArray request);
    void sendInfoRequest(QByteArray request);
    void sendDataRequest(QByteArray request);
    void packRequest(QByteArray& request);
    bool m_server_set;

    QUdpSocket m_info_sock;
    QUdpSocket m_sync_sock;
    QUdpSocket m_data_sock;

    QTimer m_timer;
    QByteArray m_request;
    QHostAddress m_server_addr;
    quint16 m_server_sync_port;
    quint16 m_server_info_port;
    quint16 m_server_data_port;

    QMutex m_req_mutex;

};

#endif // CLIENTTRANSFER_H
